package com.kassadin.server.http;

import com.kassadin.server.tcp.TcpInitializer;
import com.kassadin.server.tcp.TcpServer;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.HttpRequestEncoder;
import io.netty.handler.codec.http.HttpResponseDecoder;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * ClassName: HttpServer
 * Description: rpc http server端
 *
 * @author kang.wang03
 *         Date 16/3/15
 */
public class HttpServer extends TcpServer{
    public HttpServer(int workerMaxThread) {
        super(workerMaxThread, new TcpInitializer() {
            @Override
            public void initChannel(Channel channel) {
                // 客户端接收到的是httpResponse响应，所以要使用HttpResponseDecoder进行解码
                channel.pipeline().addLast(new HttpResponseDecoder());
                // 客户端发送的是httprequest，所以要使用HttpRequestEncoder进行编码
                channel.pipeline().addLast(new HttpRequestEncoder());
                channel.pipeline().addLast(new HttpClientInboundHandler());
            }
        });
    }
}
